<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/layout :: common_header(~{::title},~{::link})">
<title>短信模板</title>
<!-- 
  additional css  -->

</head>

<body>
	<div class="main-container">
		<div class="main-content-inner">
			<div class="page-content">
				<div class="page-header">
					<h1>短信模板</h1>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<form action="" class="form-inline" id="userForm">

							<!-- <label>模板类别：</label><input type="text" name="templateCode">
							<button class="btn btn-primary btn-rounded btn-outline btn-sm "
								type="button" onclick="search()">
								<i class="fa fa-search"></i> 查询
							</button> -->
							<button class="btn btn-success btn-sm" data-toggle="tooltip"
								data-placement="left" type="button" onclick="add()" title="添加">
								<i class="fa fa-plus"></i> 添加
							</button>
						</form>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<table id="usertable" data-toggle="table"
							data-side-pagination="server" data-striped="true"
							data-query-params="queryParams" data-pagination-loop="false"
							data-page-number="1" data-data-field="list"
							data-total-field="totalRow"
							data-content-type="application/x-www-form-urlencoded"
							data-click-to-select="true" data-pagination="true"
							data-method="post" th:data-url="@{/sms/smsTemplate/query}">
							<thead>
								<tr>
									<th data-field="id">编号</th>
									<th data-field="name">模板名称</th>
									<th data-field="code">模板编码</th>
									<th data-field="content">阿里云模板编码</th>
									<th data-field="note">模板内容</th>
									<th data-field="createTime"><i
										class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i> 创建时间</th>
									<th data-field="id" data-formatter="statusFormatter">操作</th>
								</tr>
							</thead>
						</table>
					</div>

				</div>
				<div class="row">
					<ul>
						<li>使用说明：代码根据模板编码查找对应阿里云模板编码，在发送到短信接口</li>
						<li>模板内容字段在这里只是提示作用，以配置在阿里云上面的为准</li>	
					</ul>
				</div>
				<!-- /.col -->
			</div>

		</div>
		<!-- end main container -->
	</div>

	<div th:replace="common/commonJS"></div>
	<script>

	 function queryParams(params){
		 var temp = $("#userForm").serializeJSON();
		 temp.pageSize=params.limit;   //页面大小
		 temp.pageNumber=(params.offset / params.limit) + 1;   //页码  
		 temp.sort=params.sort;      //排序列名  
		 temp.sortOrder=	 params.order; //排位命令（desc，asc）
		 return temp; 
	 }
    function statusFormatter(value,row,index){
    	return '<a href="#" onclick="edit('+value+')"><i class="fa fa-edit"></i> 修改</a>'
    	+	'&nbsp;&nbsp;<a href="#" onclick="del('+value+')"><i class="fa fa-trash"></i>删除</a>';
    }
    
    function search(){
    	$('#usertable').bootstrapTable('refresh');
    }
    function add(){
    	jp.openWindow("新增短信模板",ctx+"sms/smsTemplate/add","600px", "350px");
    }
    
    function getIdSelections() {
        return $.map($("#usertable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }

    function edit(id){
    	jp.openWindow("修改"+'短信模板',ctx+"sms/smsTemplate/edit/"+id,"600px", "350px");	
    }
    
    function del(ids){
    		jp.confirm('确定要删除选择吗？', function (){
    			 jp.loading();
          	  	$.get(ctx+"sms/smsTemplate/deleteAll?ids=" +ids, function(data){
          	  		if(data){
          	  			$('#usertable').bootstrapTable('refresh');
         	  			jp.success("删除成功");
         	  		}else{
         	  			jp.error("删除失败");
         	  		}
          	  	})

    		 }
 			
 		);
    }
    $(function () {
		  
    	$('#usertable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
            $('#delete').prop('disabled', ! $('#usertable').bootstrapTable('getSelections').length);
            $('#edit').prop('disabled', $('#usertable').bootstrapTable('getSelections').length!=1);
        });
    });
</script>
</body>
</html>